import type { postOrPutType } from "@/constants";
import type { HasId, IList, IResult } from "@/types/common";
import { getAxios, commonAxiosJson, deleteAxios, exportExcelAxios } from "@/utils/request.js";
/* 回收商品 地址 */
const url = "/back/recycle-goods";
/* 回收分类数据：获取 回收商品信息 */
export const getRecycleGoodsInfo = <T, D>(params?: D): Promise<IResult<IList<T>>> => {
  return getAxios<IList<T>, D>(url, params);
};
/* 回收分类数据：获取 回收商品详情信息 */
export const getRecycleGoodsByIdInfo = <T, D extends HasId>(params: D): Promise<IResult<T>> => {
  return getAxios<T, D>(url + "/" + params.id, params);
};
/* 回收分类数据：新增，修改回收商品信息 */
export const commonRecycleGoodsInfo = <T, D>(params: D, type: postOrPutType): Promise<IResult<T>> => {
  return commonAxiosJson<T, D>(url, params, type);
};
/* 回收分类数据：修改回收商品 排序 信息 */
export const putRecycleGoodsSortInfo = <T, D>(params: D): Promise<IResult<T>> => {
  return commonAxiosJson<T, D>(url + "/update-sort", params, "PUT");
};
/* 回收分类数据：修改回收商品上架状态 信息 */
export const putRecycleGoodsChangeOnSaleInfo = <T, D>(params: D): Promise<IResult<T>> => {
  return commonAxiosJson<T, D>(url + "/change-on-sale", params, "PUT");
};
/* 回收分类数据：删除 回收商品信息 */
export const deleteRecycleGoodsInfo = <T, D>(params: D): Promise<IResult<T>> => {
  return deleteAxios<T, D>(url, params);
};

/* 导出 回收商品信息 */
export const exportRecycleGoodsInfo = <D>(params: D): Promise<Blob> => {
  return exportExcelAxios<D>(url + "/export", "GET", params);
};

/* 导入 回收商品信息 */
export const importRecycleGoodsInfo = <T, D>(params: D): Promise<IResult<T>> => {
  return commonAxiosJson<T, D>(url + "/import", params, "POST");
};
